package com.g4.shoppingsingle.controller;

import com.g4.shoppingsingle.service.IDdUsersInfoService;
import com.g4.shoppingsingle.vo.RegisterVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "系统控制")
@Slf4j
public class SysController {
    @Autowired
    private IDdUsersInfoService iDdUsersInfoService;

    @PostMapping("/register")
    @ApiOperation("注册接口")
    public String register(@Validated RegisterVo registerVo, BindingResult result){
        log.debug("接收到用户信息:{}",registerVo);
        if (result.hasErrors()) {
            String msg = result.getFieldError()
                    .getDefaultMessage();
            //将错误信息返回
            return msg;
        }
        iDdUsersInfoService.registerUser(registerVo);
        return "login";
    }




}
